'use strict';

const AdminBaseController = require('../base');
const jwt = require('jsonwebtoken');
class SystemUserController extends AdminBaseController {
  static get serviceName() {
    return 'system.systemUser';
  }
  // 后台登录
  async login() {
    const { ctx } = this;
    const result = await this.service.login(ctx.request.body);
    // token
    const token = jwt.sign({ ...result }, ctx.app.config.keys);
    ctx.success(token);
  }
  // 获取用户信息以及权限菜单
  async getUserInfo() {
    try {
      const { ctx } = this;
      // 判断当前登录的鉴权用户token中解析到上下文
      const user = ctx.user;
      const menus = await this.service.getMenu();
      ctx.success({
        user,
        menus
      });
    } catch (e) {
      console.log(e)
    }
  }
}

module.exports = SystemUserController;
